import axios from "axios"
// 思来想去，这里用token.request回调的话传参不太方便，所以还是不用了
// import token from '@/apis/refresh_token'
const baseURL = '/back'

const active = {
    // personal代表创建的，joined代表参加的，不能同时为true
    getActives: function (page, personal, joined, size, callback) {
        axios.get(baseURL + '/activity/page', {
            headers: {
                'token': localStorage.getItem('token'),
                // 'content-type':'application/json;charset=UTF-8'
            },
            params:{
                "page": page,
                "personal": personal,
                "size": size,
                "joined": joined
            }
        }).then((res) => {
            // console.log('获取活动信息成功',res.data)
            if  (callback) {
                // console.log(callback)
                callback (res)
            }
        }).catch((err) => {
            console.warn('获取活动信息失败', err)
        })
    },
    joinActive: function (aid, callback) {
        axios.get(baseURL + '/activity/join', {
            headers: {
                'token': localStorage.getItem('token'),
            },
            params:{
                "aid": aid
            }
        }).then((res) => {
            // console.log(res.data)
            if (callback) {
                callback (res.data)
            }
        }).catch((err) => {
            // console.warn('', err)
            
        })
    },
    quitActive: function (aid, callback) {
        axios.get(baseURL + '/activity/quit', {
            headers: {
                'token': localStorage.getItem('token'),
            },
            params:{
                "aid": aid
            }
        }).then((res) => {
            // console.log('退出活动成功',res.data)
            if (callback) {
                callback(res.data)
            }
        }).catch((err) => {
            console.warn('退出活动失败', err)
        })
    },
    deleteActive: function (aid, callback) {
        axios.post(baseURL + '/activity/delete', {
                "aid": aid
            },{
                headers: {
                    'token': localStorage.getItem('token')
                }
            }
        ).then(res => {
            if (callback) {
                callback (res.data) 
            }
        }).catch((err) => {
            console.warn (err)
        })
    }
}

export default active